package com.student.client.controller;

import com.student.client.entity.Attendance;
import com.student.client.mapper.AttendanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class AttendanceController {
    @Autowired
    private AttendanceMapper attendanceMapper;
    //查询所有打卡记录接口
    @RequestMapping("/attendance")
    public List<Attendance> getAttendance() {
        return attendanceMapper.findAllAttendance();
    }

    @PostMapping("/addAttendance")
    public Integer getAttendance(@RequestParam String attendance_type,
                                 @RequestParam String start_time,
                                 @RequestParam String end_time,
                                 @RequestParam String phonenumber,
                                 @RequestParam String content,
                                 @RequestParam String photo_url) {
        Attendance attendance = new Attendance(null,attendance_type,start_time,end_time,phonenumber,content,photo_url);
        return attendanceMapper.addAttendance(attendance);
    }

    @PostMapping("/updAttendance")
    public Integer updAttendance(@RequestParam String id,
                                 @RequestParam(defaultValue = "事假") String attendance_type,
                                 @RequestParam String start_time,
                                 @RequestParam String end_time,
                                 @RequestParam String phonenumber,
                                 @RequestParam String content,
                                 @RequestParam(defaultValue = "") String photo_url) {
        return attendanceMapper.updAttendance(id,attendance_type,start_time,end_time,phonenumber,content,photo_url);
    }
    @DeleteMapping("/delAttendance")
    public Integer delAttendance(@RequestParam String id) {
        return attendanceMapper.delAttendance(id);
    }


}
